//
//  CFGuidePageViewController.m
//  WealthElves
//
//  Created by Wealthwiz on 2017/4/25.
//  Copyright © 2017年 Wealthwiz. All rights reserved.
//

#import "CFGuidePageViewController.h"

//#import "CFLoginGuideViewController.h"

#define FitWidth [UIScreen mainScreen].bounds.size.width / 375
#define FitHeight [UIScreen mainScreen].bounds.size.height / 667

@interface CFGuidePageViewController ()<UIScrollViewDelegate>

@property(nonatomic, retain)UIScrollView *scrollView;
@property(nonatomic, weak)UIButton *button;
@property(nonatomic, strong)NSMutableArray *array;

@end

@implementation CFGuidePageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.array = [[NSMutableArray alloc] init];
    for (int i = 0; i < 6; i++) {
        NSString *imageName = [NSString stringWithFormat:@"intro_page%d", i];
        if (kDevice_Is_iPhone6Plus) {
            imageName = [imageName stringByAppendingString:@"_ip6+"];
        }else if (kDevice_Is_iPhone6){
            imageName = [imageName stringByAppendingString:@"_ip6"];
        }else if (kDevice_Is_iPhone5){
            imageName = [imageName stringByAppendingString:@"_ip5"];
        }else{
            imageName = [imageName stringByAppendingString:@"_ip4"];
        }
        [self.array addObject:imageName];
    }
    
    
    
    //接口数组
    //self.array = @[@"JT_YINDAO_1", @"JT_YINDAO_2", @"JT_YINDAO_3",@"JT_YINDAO_4",@"JT_YINDAO_5"];
    
    //初始化ScrollView
    self.scrollView = [[UIScrollView alloc]initWithFrame:self.view.frame];
    _scrollView.contentSize = CGSizeMake(self.view.frame.size.width * _array.count, self.view.frame.size.height);
    _scrollView.pagingEnabled = YES;
    _scrollView.delegate = self;
    _scrollView.contentOffset = CGPointMake(0, 0);
    //添加图片
    for (NSInteger i = 0; i < _array.count; i++) {
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(i * self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height)];
        imageView.image = [UIImage imageNamed:_array[i]];
        [_scrollView addSubview:imageView];
        
        UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
        button.backgroundColor = [UIColor blueColor];
        button.frame = CGRectMake(i * kUIScreenWidth+40,  kUIScreenHeight-100, kUIScreenWidth-80,60);
        //    button.layer.cornerRadius = 20 * FitWidth;
        [button addTarget:self action:@selector(ignoreAction) forControlEvents:UIControlEventTouchUpInside];
        [button setTitle:@"立即体验" forState:UIControlStateNormal];
        
        [_scrollView addSubview:button];
    }
    [self.view addSubview:_scrollView];
    
    //初始化跳到主页的Button
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    //    button.backgroundColor = [UIColor darkGrayColor];
    button.frame = CGRectMake(300 * FitWidth, 20, 100,40);
    //    button.layer.cornerRadius = 20 * FitWidth;
    [button addTarget:self action:@selector(ignoreAction) forControlEvents:UIControlEventTouchUpInside];
    //    [button setTitle:@"跳过" forState:UIControlStateNormal];
    
  //  [self.view addSubview:button];
    
    
    
    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeSystem];
    //    button.backgroundColor = [UIColor darkGrayColor];
    button1.frame = CGRectMake(40,  kUIScreenWidth-150, kUIScreenWidth-80,100);
    //    button.layer.cornerRadius = 20 * FitWidth;
    [button1 addTarget:self action:@selector(ignoreAction) forControlEvents:UIControlEventTouchUpInside];
    //    [button setTitle:@"跳过" forState:UIControlStateNormal];
    button1.hidden = YES;
    self.button = button1;
    //[self.view addSubview:button1];
    
    
}
- (void)ignoreAction
{
    //跳转代理方法
    [self GuideViewControllerJump];
}
#pragma mark 右划跳到主页的方法
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (_scrollView.contentOffset.x
        <=(_array.count - 1)  * self.view.frame.size.width) {
        self.button.hidden = NO;
    }
    if (_scrollView.contentOffset.x
        > (_array.count - 1)  * self.view.frame.size.width + 50) {
         [self GuideViewControllerJump];
    }
}

-(void)GuideViewControllerJump{
    
    // 设置窗口的根控制器
    [(AppDelegate *)[UIApplication sharedApplication].delegate setupLoginGuideViewController];
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
